package com.camel.weixin.controller;

import com.camel.core.controller.BaseCommonController;
import com.camel.core.entity.Result;
import com.camel.core.service.BaseCommonService;
import com.camel.core.utils.ResultUtil;
import com.camel.weixin.model.WxAccount;
import com.camel.weixin.service.WxAccountService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 微信公众号管理
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/wxAccount")
public class WxAccountController extends BaseCommonController<WxAccount> {

    @Resource
    private WxAccountService<WxAccount> service;

    /**
     * 刷新TOKEN
     * <p>
     * 通过开发者ID及密码调用获取access_token接口时，需要设置访问来源IP为白名单。
     * 也可使用微信云托管免鉴权调用公众号接口能力，无需配置IP白名单。
     *
     * @param id 公众号ID
     * @return e
     */
    @PostMapping("/refreshToken/{id}")
    public Result refreshToken(@PathVariable Integer id) {
        return ResultUtil.success(service.refreshToken(id));
    }

    @Override
    public BaseCommonService<WxAccount> getiService() {
        return service;
    }

    @Override
    public String getMouduleName() {
        return "微信公众号";
    }
}
